<template>
  <div class="main-menu">
    <!-- 1.logo -->
    <div class="logo">
      <img alt="" class="img" src="@/assets/img/logo.svg" />
      <h2 v-show="!isFold" class="title">龙王管理系统</h2>
    </div>
    <div class="menu">
      <el-menu
        :collapse="isFold"
        active-text-color="#fff"
        background-color="#001529"
        default-active="3"
        text-color="#b7bdc3"
      >
        <!--   开始遍历当前用户的菜单     -->
        <template v-for="item in userMenus" :key="item.name">
          <el-sub-menu :index="item.name + ''">
            <template #title>
              <!-- 字符串: el-icon-monitor => 组件 component动态组件 -->
              <el-icon>
                <component :is="item.meta.icon" />
              </el-icon>
              <span>{{ item.meta.title }}</span>
            </template>

            <template v-for="subitem in item.children" :key="subitem.name">
              <el-menu-item :index="subitem.name + ''">
                {{ subitem.meta.title }}
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
      </el-menu>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import useLoginStore from '@/store/login/login'

const loginStore = useLoginStore()
const userMenus = loginStore.userMenus

const isFold = ref()
const handleOpen = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath)
}

// 0.定义props
defineProps({
  isFold: {
    type: Boolean,
    default: false
  }
})
</script>
<style lang="less" scoped>
.main-menu {
  height: 100%;
  background-color: #001529;
}

.logo {
  display: flex;
  height: 28px;
  padding: 12px 10px 8px 10px;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;

  .img {
    height: 100%;
    margin: 0 10px;
  }

  .title {
    font-size: 16px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
  }
}

.el-menu {
  border-right: none;
  user-select: none;
}

.el-sub-menu {
  .el-menu-item {
    padding-left: 50px !important;
    background-color: #0c2135;
  }

  .el-menu-item:hover {
    color: #fff;
  }

  .el-menu-item.is-active {
    background-color: #0a60bd;
  }
}
</style>
